home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 176-200 / scopedisk194 / nodeletev1.4 / nodelete.c < prev    next >
C/C++ Source or Header  |  1995-03-19  |  11KB  |  383 lines

  1. /* NoDelete V1.4E (C) HooverSoft 1990
  2.  
  3.        cc NoDelete +L
  4.        ln NoDelete -lc32
  5.  
  6.  
  7. */
  8.  
  9.  
  10. #ifdef AZTEC_C                                 /* Works under Manx, convert it
  11. to Lattice */
  12.                                                                        /* if
  13. you don't mind the hassle...                       */
  14.  
  15. #include<intuition/intuition.h>
  16. #include<intuition/intuitionbase.h>
  17. #include<libraries/dos.h>
  18. #include<libraries/dosextens.h>
  19. #include<stdio.h>
  20. /* #define DEBUG 1 */
  21.  
  22. char bodystring[80],extensions[10][10], titlebak[80], title[80];
  23. ULONG answer, EXT_SET = 0L,  howmany = 0L;
  24. UBYTE *position, *rindex();
  25. ULONG OVERRIDE = 0L, SILENT = 0L;
  26.  
  27. struct FileHandle *output, *Output();
  28.  
  29. struct NewWindow mywindow = {
  30.        100,0,  /* window XY origin relative to TopLeft of screen */
  31.        350,10, /* window width and height */
  32.        0,1,    /* detail and block pens */
  33.        CLOSEWINDOW+VANILLAKEY, /* IDCMP flags */
  34.        WINDOWDRAG+WINDOWDEPTH+WINDOWCLOSE+SIMPLE_REFRESH,      /* other window
  35. flags */
  36.        NULL,   /* first gadget in gadget list */
  37.        NULL,   /* custom CHECKMARK imagery */
  38.        (UBYTE *)title, /* window title */
  39.        NULL,   /* custom screen pointer */
  40.        NULL,   /* custom bitmap */
  41.        5,5,    /* minimum width and height */
  42.        640,110, /* maximum width and height */
  43.        WBENCHSCREEN    /* destination screen type */
  44.        };
  45.  
  46.  
  47. struct IntuiText body = {
  48.        1,0,
  49.        JAM1|COMPLEMENT,
  50.        30,16,
  51.        NULL,
  52.        NULL,
  53.        NULL
  54.        };
  55.  
  56. struct IntuiText fbody = {
  57.        1,0,
  58.        JAM1|COMPLEMENT,
  59.        30,5,
  60.        NULL,
  61.        (UBYTE *) "System tries to fool around...",
  62.        &body
  63.        };
  64.  
  65. struct IntuiText ok = {
  66.        1,0,
  67.        JAM1|COMPLEMENT,
  68.        6,3,
  69.        NULL,
  70.        (UBYTE *)       "Yes, Delete!",
  71.        NULL
  72.        };
  73.  
  74. struct IntuiText no = {
  75.        1,0,
  76.        JAM1|COMPLEMENT,
  77.        6,3,
  78.        NULL,
  79.        (UBYTE *)  "Oops, No Way!",
  80.        NULL
  81.        };
  82.  
  83.  
  84. struct IntuiMessage *msg, *GetMsg();
  85.  
  86. struct IntuitionBase *IntuitionBase;
  87. struct Window                  *mw, *aw, *OpenWindow();
  88. struct Library                 *DosBase;
  89. UBYTE                                          *filename;
  90. void                                           *OpenLibrary();
  91. struct Task                            *FindTask();
  92.  
  93. void NoDelete()
  94. {
  95. #asm
  96.        public  _LVOSetProtection
  97.  
  98.        movem.l d0-d7/a0-a6,-(sp)
  99. #endasm
  100.        geta4();
  101. #asm
  102.        move.l  d1,_filename
  103. #endasm
  104.  
  105.        if(EXT_SET)
  106.                {
  107.  
  108.                position = rindex(filename, '.');
  109.                if(!position)
  110.                        goto delete_anyway;
  111.                else
  112.                        {
  113.                        for(answer=0L; answer < howmany; answer++)             
  114.         
  115.                                {
  116.                                if( (strcmp( (UBYTE *) position, (UBYTE *)
  117. extensions[answer])) != 0L)
  118.                                        continue;
  119.                                else
  120.                                        goto request;
  121.                                }
  122.                        }
  123.                goto delete_anyway;             
  124.                }       
  125. request:
  126.        strcpy(bodystring, "Delete File `");
  127.        strcat(bodystring, (char *)filename);
  128.        strcat(bodystring, "'?");
  129.        body.IText = (UBYTE *) bodystring;
  130.        aw = (struct Window *) IntuitionBase->ActiveWindow;
  131.        answer = (long)AutoRequest(aw, &fbody, &ok, &no, NULL, NULL, 360L,
  132. 61L);
  133.        if(!answer)ecsvax
  134.  
  135.        {
  136.                ;
  137. #asm
  138.        movem.l (sp)+,d0-d7/a0-a6
  139.        move.l  #1,d0
  140. #endasm
  141.        return;
  142.        }
  143.  
  144.        if(answer)
  145.        {
  146.  
  147. delete_anyway:
  148.                ;
  149. #asm
  150.  
  151.                move.l  _DosBase,a6             
  152.                move.l  #$70f7,d0                       ;restore old vector
  153.                move.w  d0,-72(a6)
  154.                move.l  #$60000092,d0
  155.                move.l  d0,-70(a6)
  156.                
  157.                tst.l           _OVERRIDE
  158.                beq.s           _dont_unprotect
  159.  
  160.                move.l  _filename,d1
  161.  
  162.  
  163.                move.l  #0,d2
  164.                jsr             _LVOSetProtection(a6)
  165.  
  166. _dont_unprotect:
  167.  
  168.                move.l  _filename,d1
  169.                jsr             -72(a6)                         ;DeleteFile()
  170. call
  171. #endasm
  172.  
  173.                ;
  174.  
  175.                SetFunction(DosBase, -72L, &NoDelete);
  176.  
  177. /* install our function */
  178.  
  179.  
  180. #asm
  181.                movem.l (sp)+,d0-d7/a0-a6
  182.                move.l  #1,d0
  183. #endasm
  184.                return;
  185.                }
  186.        }
  187.                
  188.  
  189. void quit(why)
  190. UBYTE *why;
  191. {
  192.        if(!SILENT)
  193.                Write(output, why, (ULONG) strlen(why) );
  194.        SetTaskPri((struct Task *)FindTask(0L), 0L);
  195.        if(DosBase)
  196.        {
  197.                ;
  198. #asm
  199.                move.l  _DosBase,a6             
  200.                move.l  #$70f7,d0                       ;restore old vector
  201.                move.w  d0,-72(a6)
  202.                move.l  #$60000092,d0
  203.                move.l  d0,-70(a6)
  204. #endasm
  205.                ;
  206.        }
  207.  
  208.        if      (mw)
  209.                CloseWindow(mw);
  210.  
  211.        if (DosBase)    
  212.                CloseLibrary(DosBase);
  213.  
  214.        if (IntuitionBase)
  215.                CloseLibrary(IntuitionBase);
  216.  
  217.        exit(0L);
  218. }
  219.  
  220. /* test_nd() tests the DeleteFile vector to see if NoDelete is already 
  221.        installed. Returns zero if NoDelete is installed, one if it is not.
  222. */
  223. #asm
  224.                public  _test_nd
  225. _test_nd:
  226.  
  227.                move.l  _DosBase,a6
  228.                cmpi.l  #$60000092,-70(a6)
  229.                bne.s           _is_there                               
  230.                moveq           #1,d0
  231.                bra.s           _fuckoff
  232. _is_there:
  233.                moveq           #0,d0
  234. _fuckoff:
  235.                rts     
  236. #endasm
  237. void main(argc,argv)
  238. long argc;
  239. char *argv[];
  240.        {
  241.  
  242.        static UBYTE *msg1 = (UBYTE *)"Installing NoDelete...";
  243.        static UBYTE *msg2 = (UBYTE *)"done. NoDelete V1.4E (c) HooverSoft
  244. 1990\n\n";
  245.        long i;
  246.  
  247.        DosBase = (struct Library *) OpenLibrary("dos.library",0L);
  248.        output = Output();
  249.        strcpy(title, (UBYTE *) "NoDelete V1.4E (c) HooverSoft");
  250.        
  251.        if(argc > 11)
  252.                quit("Sorry, only 10 extensions allowed!\n");
  253.  
  254.        if(argc >= 2)
  255.                {
  256.                for(i=1; i<argc; i++)
  257.                        {
  258.        
  259.                        if(argv[i][0] == '.')
  260.                                {
  261.                                EXT_SET = 1L;
  262.                                strcpy(extensions[howmany], argv[i]);
  263.                                howmany++;
  264.                                }
  265.                        else
  266.                         continue;
  267.  
  268. #ifdef DEBUG
  269.                        printf("Copied %s, Result: %s\n", argv[i],
  270. extensions[i-1L]);
  271. #endif 
  272.                        }
  273.  
  274. #ifdef DEBUG
  275.                printf("I found %ld extensions.\n", howmany);
  276. #endif                 
  277.  
  278.  
  279.                if(howmany)
  280.                                strcat(title, (UBYTE *) " EXT SET");           
  281.         
  282.  
  283.                for(i=1; i<argc; i++)
  284.                        {
  285. #ifdef DEBUG
  286.                        printf("Scanning argv[%ld]: %s\n", i, (UBYTE *) argv[i]
  287. );
  288. #endif
  289.                        if( (char) argv[i][0] == '-')
  290.                                switch( (char) argv[i][1] )
  291.                                        {
  292.                                        case 'y':       if( atoi(argv[i+1]) <=
  293. 245L)
  294.                                                                               
  295. mywindow.TopEdge = atoi(argv[i+1]);
  296.                                                                        break;
  297.  
  298.                                        case 'p':       if(atoi(argv[i+1]) <
  299. 10L && atoi(argv[i+1]) > -20L)
  300.                                                                               
  301. SetTaskPri((struct Task *)FindTask(0L),\
  302.                                                                               
  303.                                 (long)atoi(argv[i+1]));
  304.                                                                        else
  305.                                                                               
  306. SetTaskPri((struct Task *)FindTask(0L), -5L);
  307.                                                                        break;
  308.  
  309.                                        case  'O':      OVERRIDE = 1L;
  310.                                                                        break;
  311.                                
  312.                                        case  'S':      SILENT = 1L;
  313.                                                                        break;
  314.                                
  315.                                        case default: break;
  316.                                        }
  317.                                /* end switch */
  318.                        /*end if */
  319.                /*end for */
  320.                        }       
  321.                                        
  322.                }
  323.  
  324.        if(!howmany)
  325.                {
  326.                EXT_SET = 0L;
  327.                strcat(title, (UBYTE *) " NO EXT");
  328.                }
  329.  
  330. /* calculate dimension of TitleBar */
  331.  
  332.        mywindow.Width = ( strlen(title) * 8L) + 85L;
  333.        mywindow.LeftEdge = (640L-mywindow.Width) / 2L;
  334.  
  335.        IntuitionBase =  OpenLibrary("intuition.library",0L);
  336.        if(!SILENT)
  337.                Write(output, msg1, (ULONG)strlen(msg1));
  338.  
  339.        if( !test_nd() && !SILENT )
  340.                {
  341.                Write(output, "NoDelete already installed.\n",28L);
  342.                CloseLibrary(DosBase);
  343.                CloseLibrary(IntuitionBase);
  344.                exit(0L);
  345.                }
  346.  
  347.        mw = OpenWindow(&mywindow);
  348.        if(!mw)
  349.                quit("Could not open Window.\n\n");
  350.        if(!SILENT)
  351.                Write(output, msg2, (ULONG)strlen(msg2));
  352.  
  353.        SetFunction(DosBase, -72L, &NoDelete); 
  354.  
  355.        for(;;)
  356.                {
  357.                Wait(1L << mw->UserPort->mp_SigBit);
  358. getmsg:
  359.                msg = GetMsg(mw->UserPort);
  360.                ReplyMsg(msg);
  361.                if (msg->Class == CLOSEWINDOW)
  362.                        quit("NoDelete V1.4E exiting.\n\n");
  363.                if(msg->Class == VANILLAKEY)
  364.                        {
  365.                        strcpy(titlebak, (UBYTE *) "Extensions: ");
  366.                        for(i=0L; i < howmany ; i++)
  367.                                {
  368.                                strcat(titlebak, extensions[i]);
  369.                                strcat(titlebak, " ");
  370.                                }
  371.                        SetWindowTitles(mw, titlebak);
  372.                        Wait(1L << mw->UserPort->mp_SigBit);
  373.                        SetWindowTitles(mw, title);
  374.                        ReplyMsg( GetMsg(mw->UserPort) );
  375.                        }
  376.  
  377.                else
  378.                        continue;
  379.                }
  380.        }
  381. #endif 
  382.        
  383.